package com.ym9527.controller;


import com.ym9527.controller.apiEntity.AddTeacherAE;
import com.ym9527.entity.User;
import com.ym9527.jpa.UserJpa;
import com.ym9527.utils.R;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("adminRelevant")
public class AdminRelevantController {

    @Resource
    UserJpa userJpa;

    /**
     * 这是增加老师接口
     * @return
     */
    @PostMapping("addTeacher")
    @Transactional()
    public R addTeacher(HttpServletRequest request, AddTeacherAE addTeacherAE){


        User user=new User();

        user.setUserName(addTeacherAE.getTeacherName());
        user.setPassword(addTeacherAE.getPassWorld());

        userJpa.save(user);

        return R.ok("添加成功");
    }

    /**
     * 这是删除老师接口
     * @return
     */
    @GetMapping("deleteTeacher")
    @Transactional()
    public R deleteTeacher(@RequestParam Long userId){

        User user=userJpa.getById(userId);

        userJpa.delete(user);

        return R.ok("删除成功");
    }



}
